package com.yhb.service.impl;

import com.yhb.dao.LogMapper;
import com.yhb.service.LogService;
import com.yhb.utils.DateUtils;
import lombok.extern.log4j.Log4j;
import me.edzh.spring.bootstrap.utils.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Log4j
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Async
    @Override
    public void insertLog(String dateString, String userId, String type, Object content) {
        try {
            logMapper.insertLog(dateString, userId, type, JSONUtil.toJson(content));
        } catch (Throwable t) {
            log.error("error when print log:", t);
        }
    }

    @Override
    public void insertLog(String userId, String type, Object content) {
        this.insertLog(DateUtils.getCurrentDateString(), userId, type, content);
    }
}
